package com.atguigu.gulimall.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author wzb
 * @version V1.0
 * @Package com.atguigu.gulimall.product.config
 * @date 2022-08-10 11:21
 * @Copyright ©
 */
//@EnableConfigurationProperties({ThreadPoolConfigProperties.class})
@Configuration
public class MyThreadConfig {


    /**
     * 自定义线程池：
     * 1、核心线程数 20
     * 2、最大线程数200
     * 3、线程空闲存活时间 10
     * 4、存活单位 秒
     * 5、阻塞队列：最多存储10万的任务
     * 6、默认的线程工厂
     * 7、策略：拒绝策略
     *
     * @return
     */
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfigProperties pool) {
        return new ThreadPoolExecutor(pool.getCoreSize(), pool.getMaxSize(), pool.getKeepAliveTime(),
                TimeUnit.SECONDS, new LinkedBlockingDeque<>(100000),
                Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());

    }


}
